const electron = require('electron');
const {Menu, BrowserWindow} = electron;
var template = [ // 菜单是个数组
    {   // 里面的菜单都是对象
        label: '大菜单',
        submenu: [
            {
                label: '小菜单1', // 标签名是必须的
                click: () => { // 点击事件
                    var win = new BrowserWindow({
                        width: 300,
                        height: 300,
                        nodeIntegration: true,
                        contextIsolation: false,
                        enableRemoteModule: true,
                    });
                    win.loadFile('yellow.html'); // 神奇，这里竟然不用写../
                    win.on('close', () => {
                        win = null;
                    })
                },
                accelerator: 'ctrl+n', // 设置快捷键
            },
            {label: '小菜单2'},
        ],
    },
    {
        label: '另一个大菜单',
        submenu: [
            {label: '子菜单'},
        ],
    },
];

var m = Menu.buildFromTemplate(template);

Menu.setApplicationMenu(m);